<script>
import { mapState } from 'vuex'
import { zoneGetlistApi, reportViewpdfApi, requestApi } from '@/requset/api'
import { formConfig, config, column } from './formConfig.js'
import SearchManage from '@/components/basic/SearchManage.vue'
import { deepClone } from '@/plugins/clone'
export default {
    extends: SearchManage,
    data() {
        return {
            table_title: '故障案例',
            url: 'report',
            actions: [
                {
                    label: '批量删除',
                    icon: 'el-icon-delete',
                    click: () => {
                        this.deletes()
                    },
                    if: () => this.operate,
                },
                {
                    label: '添加',
                    icon: 'el-icon-folder-add',
                    click: () => {
                        this.handleAdd()
                    },
                    if: () => this.operate,
                },
            ],
            baseForm: {
                title: null,

                filepath: null,
            },
            queryForm: {
                title: null,
                scope_id: null,
                scope_id_list: [],
                start_time: null,
                end_time: null,
                maker: null,
                status: null,
                type: 3,
                page: 1,
                size: 20,
            },
            queryFormC: {
                title: null,
                scope_id: null,
                scope_id_list: [],
                start_time: null,
                end_time: null,
                maker: null,
                status: null,
                type: 3,
                page: 1,
                size: 20,
            },
        }
    },
    methods: {
        reportViewpdf(filename) {
            reportViewpdfApi(filename)
        },
        add(data) {
            data.type = 3
            requestApi('post', this.url + '/add', this.to(deepClone(data))).then((res) => {
                if (res.data.code == 0) {
                    this.$message({
                        type: 'success',
                        message: '添加成功',
                    })
                    this.getlist()
                    this.$refs.zyform.closeDialog()
                }
            })
        },
    },
    computed: {
        ...mapState('backstage', ['backstageData', 'deviceType']),
        tags() {
            if (this.pagination.total !== undefined) {
                return [{ title: '总数', num: this.pagination.total }, null, { title: '编辑中', num: this.stat.editing }, { title: '已完成', num: this.stat.completed }]
            } else return []
        },
    },
    created() {
        this.searchBtn()

        this.formConfig = formConfig
        this.dialog.config = config
        column[column.length - 1].buttons = [
            {
                text: '下载',
                click: (val) => this.reportViewpdf(val.filepath),
                if: (val) => val.filepath !== 'None',
                icon: 'el-icon-download',
            },
            {
                text: '删除',
                click: (val) => this.delete(val),
                icon: 'el-icon-delete',
            },
        ]
        column[column.length - 1].if = this.operate
        this.tableColumn = column
    },
}
</script>
